const express = require('express')

const app = express();

const path = require('path')

const router = require('./routers/apiRouter')

const mysql = require('mysql2');

const pool =mysql.createPool({
    host: 'localhost',
    user: 'root',
    password1: '123456',
    database:'riddle_game'
})

 exeSql = async (sql)=>{
    const promisePool = pool.promise()
    const [rows,fields]=await promisePool.query(sql)
    return {rows,fields}
}

app.use((req,res,next)=>{
    res.exeSql =exeSql
    next()
})

// app.all('/api/*',(req,res,next)=>{
//     res.header('Access-Control-Allow-Origin','*')
//     res.header('Access-Control-Allow-Methods','*')
//     res.header('Access-Control-Allow-Headers','*')
// })

const apiRoute = require('./routers/apiRouter.js')
app.use('/',apiRoute)


app.listen(2024,()=>{
    console.log("韵妍持续跑步中....");
})